/**
 * Moondance UML modeling tool
 * 
 * @author Dascalu Laurentiu (dascalu.laurentziu@gmail.com).
 * 
 * This program is free software; you can redistribute it and
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package ro.pub.cs.se.moondance.xmi.converter;

import java.util.Iterator;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import ro.pub.cs.se.moondance.model.ClassFunction;
import ro.pub.cs.se.moondance.model.ClassVariable;
import ro.pub.cs.se.moondance.model.UMLInterface;

public class UMLInterfaceXMI extends UMLBlockXMI {

	/**
	 * Example
	 * <packagedElement
	 *     xmi:type="uml:Interface"
	 *     xmi:id="_RRTvIGcJEd67F_7YoWwK5g"
	 *     name="SomeInterface"/>
	 * May contain attributes and operations. See UMLBlockXMI.serialize() functions for
	 *     informations about the format.
	 */

	public UMLInterfaceXMI(String name, String id) {
		super(XMICommon.UML_INTERFACE, name, id);
	}
	
	public void serialize(Element root, Document document, UMLInterface myInterface,
			boolean addConnections) {
		
		if (addConnections) {
			serializeConnections(root, document, myInterface);
			return;
		}
		
		// Look at the above example for more details
		currentElement = document.createElement(XMICommon.PACKED_ELEMENT);
		currentElement.setAttribute(XMICommon.XMI_TYPE, type);
		currentElement.setAttribute(XMICommon.XMI_ID, id);
		currentElement.setAttribute(XMICommon.NAME, name);
		
		if (myInterface.isAbstract())
			currentElement.setAttribute(XMICommon.IS_ABSTRACT, "true");
		currentElement.setAttribute(XMICommon.VISIBILITY, myInterface.getVisibility());
		
		root.appendChild(currentElement);
			
		// Add attributes (class member variables)
		List<ClassVariable> attributes = myInterface.getAttributes();

		for(Iterator<ClassVariable> it = attributes.iterator();
			it.hasNext();
			serialize(currentElement, document, it.next()));
		
		// Add operations (class member functions)
		List<ClassFunction> operations = myInterface.getOperations();
		
		for(Iterator<ClassFunction> it = operations.iterator();
			it.hasNext();
			serialize(currentElement, document, it.next()));
	}
}
